package com.cy.web;


import com.cy.bean.Cartable;
import com.cy.bean.Driverschool;
import com.cy.bean.Driverschoolcomplaint;
import com.cy.service.ComplaintService;
import com.cy.token.JwtUtil;
import com.cy.token.ResultResponse;
import com.cy.util.CacheRedisService;
import com.cy.util.DayRange;
import com.cy.util.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class ComplaintController {
    @Autowired
    private ComplaintService complaintService;
    @Autowired
    private CacheRedisService cacheRedisService;

    @GetMapping("/getComplaintList")
    public ResultResponse getComplaintList(DayRange dayRange, HttpSession httpSession){

        int did= Integer.parseInt(cacheRedisService.get("did"));

        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(20000);
        resultResponse.setMessage(JwtUtil.TOKEN_SUCCESS);
        resultResponse.setData(complaintService.getComplaintList(did, dayRange.getStartDay(), dayRange.getEndDay()));
        return resultResponse;
    }

    @PostMapping("/replyComplaint")
    public ResultResponse replyComplaint(@RequestBody Driverschoolcomplaint driverschoolcomplaint, HttpSession httpSession,DayRange dayRange){

        int did= Integer.parseInt(cacheRedisService.get("did"));
        String reptime= Util.getDate();
        driverschoolcomplaint.setReplytime(reptime);
        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(20000);
        resultResponse.setMessage(JwtUtil.TOKEN_SUCCESS);

        if (complaintService.replyComplaint(driverschoolcomplaint)>0){
            resultResponse.setData(complaintService.getComplaintList(did, dayRange.getStartDay(), dayRange.getEndDay()));
        }
        return resultResponse;
    }
}
